import { FormBase } from './../../shared/from/form-base';
import { Injectable } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';


@Injectable()
export class formControlService {
    constructor() { }

    toFormGroup(forms: FormBase<any>[]) {
        let group: any = {};

        forms.forEach(form => {
            group[form.key] = form.required ? new FormControl(form.value || '', Validators.required)
                : new FormControl(form.value || '');
        });
        return new FormGroup(group);
    }
}
